import { observable, action } from 'mobx';
import _ from 'lodash';
import CardStore from ".";
import { WeaLocaleProvider } from "ecCom";
const { formatMultiLang } = WeaLocaleProvider;
const getLabel = WeaLocaleProvider.getLabel;

export default class MapStore {
    card: CardStore;
    constructor(card: CardStore) {
        this.card = card;
    }
    @observable mapAttrs: any = {};
    @observable visible: boolean = false;
    @observable defaultAddress: string = "";
    currentField: string = "";
    lnglat: any = [];
    @observable showButtons = false;

    form: any;

    @action
    updateParams = (params: any) => {
        // this.baseParams = {customid:params.customid};
        // this.query();
        // this.search();
        // this.getRightMenus();
    }


    getMapAttr = (key: string) => {
        return _.get(this.mapAttrs, key);
    }
    @action
    onCancel = () => {
        this.visible = false;
    }

    @action
    onShow = (value: string, path: string, form: any) => {
        if (value.startsWith("~`~`") && value.endsWith("`~`~")) {
            value = formatMultiLang(value);
        }
        this.defaultAddress = value;
        this.currentField = path;
        this.form = form;
        this.visible = true;
        this.lnglat = form.$(this.currentField)["lnglat"];
    }

    @action
    updateAddress = (value: string, lnglat: any = []) => {
        if (value.startsWith("~`~`") && value.endsWith("`~`~")) {
            value = formatMultiLang(value);
        }
        this.defaultAddress = value.replace(getLabel(34177, "当前位置") + ":", "");
        this.lnglat = lnglat;
    }

    @action
    getLocation = () => {
        this.form.$(this.currentField).onChange(this.form.$(this.currentField).getValue() + this.defaultAddress);
        this.onCancel();
    }

    @action
    getLocationCover = () => {
        this.form.$(this.currentField).onChange(this.defaultAddress);
        this.form.$(this.currentField)["lnglat"] = this.lnglat;
        this.onCancel();
    }
}